package cn.cvs.utils;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class AddressLogger {

    @Pointcut("execution(* cn.cvs.service..*.*(..))")
    public void pointcut(){}
    /*前置增强*/
    @Before("pointcut()")
    public void before(JoinPoint joinPoint) {
        System.out.println("调用" + joinPoint.getTarget()
                + "的" + joinPoint.getSignature().getName()
                + "方法。方法入参：" + Arrays.toString(joinPoint.getArgs()));
    }
    /*后置增强*/
    @AfterReturning(pointcut ="pointcut()",returning = "result")
    public void after(JoinPoint joinPoint,Object result){
        System.out.println("调用" + joinPoint.getTarget()
                + "的" + joinPoint.getSignature().getName()
                + "方法。返回值：" + result);
    }
}
